package com.example.leetcode.leetcode.hot100;

import java.util.*;

/**
 * @author haitao
 * @date 2022/6/8 5:27 下午
 * 两数之和
 */
class Solution1 {

    public int[] twoSum(int[] nums, int target) {
        int [] res = new int[2];
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            if(list.contains(target-nums[i])){
                res[0] = list.indexOf(target-nums[i]);
                res[1] = i ;
            }else {
                list.add(nums[i]);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Solution1 solution1 = new Solution1();
        int[] nums = {3,3};
        System.out.println(Arrays.toString(solution1.twoSum(nums, 6)));
    }
}
